﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LNBMS.DAL.PetaPoco;
using System.Configuration;
using LNBMS.Entity;

namespace LNBMS.DAL
{
    public class InformationInputDAL
    {
        private Database _db = new Database(ConfigurationManager.ConnectionStrings["npgSqlStr"].ConnectionString, "Npgsql");

        #region 增删改查
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="entity">实体类</param>
        /// <returns></returns>
        public bool Insert(InformationInput entity)
        {
            bool isOk = _db.Insert(entity) != null ? true : false;
            return isOk;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="entity">实体类</param>
        /// <returns></returns>
        public bool Update(InformationInput entity)
        {
            bool isOk = _db.Update(entity) > 0 ? true : false;
            return isOk;
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="KeyValue">主键</param>
        /// <returns></returns>
        public bool Delete(string KeyValue)
        {
            bool isOk = _db.Delete<InformationInput>(KeyValue) == 1 ? true : false;
            return isOk;
        }
        /// <summary>
        /// 根据一个主键得到一个实体
        /// </summary>
        /// <param name="KeyValue"></param>
        /// <returns></returns>
        public InformationInput GetEntity(string KeyValue)
        {
            try
            {
                return _db.Single<InformationInput>("SELECT * FROM \"InformationInput\" WHERE cardid='"+KeyValue+"'");
            }
            catch (System.InvalidOperationException)
            {
                return null;
            }

        }
        #endregion
    }
}
